package com.hanyxp.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DataPool {
	/**
	 * 获得一个Connection
	 * @throws Exception 连接异常
	 * @return 返回一个{@link Connection}实例
	 */
	public Connection getCon() {
		try {
			Class.forName("org.logicalcobwebs.proxool.ProxoolDriver");
			return DriverManager.getConnection("proxool.exlesson");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
	/**
	 * 关闭一个Connection连接
	 * @param {@link Connection} con
	 */
	public void closeCon(Connection con) {
		try {
			con.close();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	/**
	 * 执行一条SQL
	 * @param sql
	 * @param con
	 * @return
	 */
	public static ResultSet execSql(String sql , Connection con){
		ResultSet rs = null;
		try {
			rs = con.createStatement().executeQuery(sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return rs;
	}
	/**
	 * 
	 * @param sql
	 * @param con
	 * @return
	 */
	public static int execUpdate(String sql, Connection con){
		int i = 0;
		try {
			i = con.createStatement().executeUpdate(sql);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return i;
	}
	
}
